package algotithm.acwing.test898;

import java.io.IOException;
import java.util.Scanner;

/**
 * @author zhouyanxiang
 * @Date 2021-01-2021/1/10-19:16
 */
public class Main {

    public static void main(String[] args) throws IOException {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[][] arr = new int[510][510];
        int[] f = new int[510];
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= i; j++) {
                arr[i][j] = scanner.nextInt();
            }
        }
        for (int i = n; i >= 1; i--) {
            for (int j = 1; j <= i; j++) {
                f[j] = Math.max(f[j+1],f[j]) + arr[i][j];
            }
        }
        System.out.println(f[1]);
    }

}
